package components.dialogs
{
	import UIFree.ObjectEvent;
	import UIFree.command.ICommand;
	import UIFree.command.uif_commandManager;
	import UIFree.uif_component;
	
	import classes.c_events;
	
	import components.editor.c_baseElement;
	
	import flash.events.Event;
	
	public class c_elementPropDlg extends c_propertyDialog {
		private static var _listDialogs	: c_elemDlgList;
		private var _element			: c_baseElement;
		public function c_elementPropDlg(parent:uif_component, a_element: c_baseElement, propertyList:Array, a_title:String='', modal:Boolean=false, canClose:int=2) {
			super(parent, propertyList, a_title, modal, canClose);
			if (!_listDialogs) _listDialogs = new c_elemDlgList(cl.workspace);
			
			setElement(a_element);
			_listDialogs.pushDlg(this);
		}
		
		public static function count(): int {
			return _listDialogs?_listDialogs.length:0;
		}
		
		override public function dispose():void {
			_listDialogs.deleteDlg(this);
			super.dispose();
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(c_events.CHANGECURRENTELEMENT, doChangeCurrentElement, cl.workspace);
		}
		
		protected function doChangeCurrentElement(e: ObjectEvent): void {
			//setElement(e.object as c_baseElement);
			doApply();
			close(0);
		}
		
		protected function setElement(a_element: c_baseElement): void {
			_element = a_element;
			if (!_element) close();
			else updateElement();
		}
		
		protected function get element(): c_baseElement {
			return _element;
		}
		
		override protected function doChange(e: Event):void {
			updateElement();
		}
		
		protected function updateElement(): void {
		}
	}
}